package org.example.utlis;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.form.PageForm;

/**
 * @author joey
 */
public class PageUtil {
    public static final long MAX_PAGE_SIZE=999;
    public static final long INIT_PAGE_NO=1;
    public static final long INIT_PAGE_SIZE=10;

    public static Page getPage(PageForm form) {

        if (form == null) {
            return new Page<>(INIT_PAGE_NO, INIT_PAGE_SIZE);
        }
        return new Page<>(form.getPageNo() == null || form.getPageNo() < INIT_PAGE_NO ? INIT_PAGE_NO : form.getPageNo(),
                form.getPageSize() == null || form.getPageSize() < INIT_PAGE_NO ? INIT_PAGE_SIZE : form.getPageSize(),
                StrUtil.isEmpty(form.getPageStatus()));
    }

    public static Page getMaxPage(){
        return new Page<>(INIT_PAGE_NO,MAX_PAGE_SIZE);
    }
}